<!DOCTYPE html>

<html class="no-js">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />

  <script src="https://cdn.staticfile.org/axios/0.19.0-beta.1/axios.js"></script>

  <script src="../../cdn/vue/vue.global.min.js"></script>
  <link rel="stylesheet" href="../../cdn/element-plus/index.css" />
  <script src="../../cdn/element-plus/index.full.min.js"></script>
  <link rel="stylesheet" href="../../../lib/index.css" />
  <script src="../../../lib/avue.js"></script>
</head>

<body>
  <div id="app">
    <avue-crud :data="data" :option="option" @row-save="rowSave" @row-update="rowUpdate" @row-del="rowDel"
      @refresh-change="refresh"></avue-crud>
  </div>
</body>
<script>

  var app = Vue.createApp({
    data() {
      return {
        data: [
          {
            id: 1,
            name: '张三',
            sex: '男'
          }, {
            id: 2,
            name: '李四',
            sex: '女'
          }
        ],
        option: {
          page: false,
          align: 'center',
          menuAlign: 'center',
          menuWidth: 400,
          viewBtn: true,
          column: [
            {
              label: '姓名',
              prop: 'name'
            }, {
              label: '性别',
              prop: 'sex'
            }
          ]
        },
      };
    },
    methods: {

      refresh(val) {
        this.$message.success('刷新回调,当前分页对象' + JSON.stringify(val));
      },
      rowDel(form, index, done) {
        done(form);
        this.$message.success('删除数据' + JSON.stringify(form));
      },
      rowSave(form, done, loading) {
        this.$message.success('模拟网络请求')
        setTimeout(() => {
          this.$message.success('关闭按钮等待');
          loading();
        }, 1000)
        setTimeout(() => {
          this.$message.success('新增数据' + JSON.stringify(form));
          form.id=this.data.length
          done(form);
        }, 2000)
      },
      rowUpdate(form, index, done, loading) {
        this.$message.success('模拟网络请求')
        setTimeout(() => {
          this.$message.success('关闭按钮等待');
          loading();
        }, 1000)
        setTimeout(() => {
          this.$message.success('编辑数据' + JSON.stringify(form) + '数据序号' + index);
          done(form);
        }, 2000)
      },
    }
  })
  app.use(ElementPlus)
  app.use(AVUE)
  app.mount('#app')
</script>

</html>